﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EbayQueryExpertLib.Entities
{
    public class EbaySiteInfo
    {
        private static readonly EbaySiteInfo[] m_AllEbaySites = new EbaySiteInfo[]{
            new EbaySiteInfo("EBAY-AT", "de-AT", "AT", "eBay Austria", 16),
            new EbaySiteInfo("EBAY-AU", "en-AU", "AU", "eBay Australia", 15),
            new EbaySiteInfo("EBAY-CH", "de-CH", "CH", "eBay Switzerland", 193),
            new EbaySiteInfo("EBAY-DE", "en-DE", "DE", "eBay Germany", 77),
            new EbaySiteInfo("EBAY-ENCA", "en-CA", "CA", "eBay Canada (English)", 2),
            new EbaySiteInfo("EBAY-ES", "es-ES", "ES", "eBay Spain", 186),
            new EbaySiteInfo("EBAY-FR", "fr-FR", "FR", "eBay France", 71),
            new EbaySiteInfo("EBAY-FRBE", "fr-BE", "BE", "eBay Belgium (French)", 23),
            new EbaySiteInfo("EBAY-FRCA", "fr-CA", "CA", "eBay Canada (French)", 210),
            new EbaySiteInfo("EBAY-GB", "en-GB", "GB", "eBay UK", 3),
            new EbaySiteInfo("EBAY-HK", "zh-Hant", "HK", "eBay Hong Kong", 201),
            new EbaySiteInfo("EBAY-IE", "en-IE", "IE", "eBay Ireland", 205),
            new EbaySiteInfo("EBAY-IN", "en-IN", "IN", "eBay India", 203),
            new EbaySiteInfo("EBAY-IT", "it-IT", "IT", "eBay Italy", 101),
            new EbaySiteInfo("EBAY-MOTOR", "en-US", "US", "eBay Motors", 100),
            new EbaySiteInfo("EBAY-MY", "en-MY", "MY", "eBay Malaysia", 207),
            new EbaySiteInfo("EBAY-NL", "nl-NL", "NL", "eBay Netherlands", 146),
            new EbaySiteInfo("EBAY-NLBE", "nl-BE", "BE", "eBay Belgium (Dutch)", 123),
            new EbaySiteInfo("EBAY-PH", "en-PH", "PH", "eBay Philippines", 211),
            new EbaySiteInfo("EBAY-PL", "pl-PL", "PL", "eBay Poland", 212),
            new EbaySiteInfo("EBAY-SG", "en-SG", "SG", "eBay Singapore", 216),
            new EbaySiteInfo("EBAY-US", "en-US", "US", "eBay United States", 0),
        };
        
        //******************************************************************************************************

        private static bool m_Loaded = false;
        private static readonly Dictionary<int, EbaySiteInfo> m_EbaySitesById = new Dictionary<int, EbaySiteInfo>();
        private static readonly Dictionary<string, EbaySiteInfo> m_EbaySitesByGlobalId = new Dictionary<string, EbaySiteInfo>();

        public static Dictionary<int, EbaySiteInfo> EbaySitesById
        {
            get
            {
                if (!m_Loaded)
                    Load();
                return m_EbaySitesById;
            }
        }
        public static Dictionary<string, EbaySiteInfo> EbaySitesByGlobalId
        {
            get
            {
                if (!m_Loaded)
                    Load();
                return m_EbaySitesByGlobalId;
            }
        }
        private static void Load()
        {
            if (m_Loaded)
                return;
            m_EbaySitesById.Clear();
            foreach( EbaySiteInfo nfo in m_AllEbaySites )
            {
                m_EbaySitesById.Add(nfo.Id, nfo);
                m_EbaySitesByGlobalId.Add(nfo.GlobalId, nfo);
            }
            m_Loaded = true;
        }

        //******************************************************************************************************

        private readonly string m_Name;
        private readonly string m_Language;
        private readonly string m_GlobalId;
        private readonly string m_Territory;
        private readonly int m_Id;

        public string Language
        {
            get { return m_Language; }
        } 


        public string GlobalId
        {
            get { return m_GlobalId; }
        } 


        public string Territory
        {
            get { return m_Territory; }
        } 


        public string Name
        {
            get { return m_Name; }
        }

        public int Id
        {
            get { return m_Id; }
        }

        public EbaySiteInfo(string globId, string lang, string terr, string name, int id)
        {
            m_Id = id;
            m_Name = name;
            m_GlobalId = globId;
            m_Territory = terr;
            m_Language = lang;
        }

        public override string ToString()
        {
            return m_Name;
        }
    }
}
